import {FC, useEffect, useState} from "react";
import {BookConfig, getBookHistoryList} from "@/apis/recommend";
import {ApiConstants} from "@/apis/constants";

export const History: FC = () => {
    const [historyList, setHistoryList] = useState<BookConfig[]>([])
    useEffect(() => {
        async function loadData() {
            const {code, data} = await getBookHistoryList(15)
            if (code !== ApiConstants.SUCCESS) return null
            setHistoryList(data)
        }

        loadData()
    }, [])
    return (
        <div className="history">
            <div className="history_card">
                <h4>最近浏览</h4>
                {
                    historyList.map(item => <p key={item.id}><a href={item.link} rel="noreferrer" target="_blank">{`${item.author}  ${item.name}`}</a></p>)
                }
            </div>
        </div>

    )
}
